home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-27 | 5.1 KB | 251 lines | [TEXT/CWIE] |
- // =======================================================================
- // 3D Class Library, © Xilex Group
- // - ------------------------------------------------------------------- -
- // Written by Dmitry Boldyrev
- // =======================================================================
-
- #pragma once
-
- #include "types.h"
- #include "cosin.h"
- #include <math.h>
-
- #include "LinkList.h"
-
- typedef WORD matrix3d[3][3];
-
- typedef struct
- {
- WORD x; // x coordinate in space
- WORD y; // y coordinate in space
- WORD z; // z coordinate in space
- } vector3d;
-
- typedef struct
- {
- WORD x; // x projected coordinate
- WORD y; // y projected coordinate
- WORD c; // color/intensity of the edge
- WORD u; // x texture coordinate
- WORD v; // y texture coordinate
- } upoint;
-
- enum {
- isVertex, // vertex is a VERTEX
- isNormal // vertex is a normal
- };
-
- class vertex : public ListNode
- {
- public:
- vector3d xyz; // xyz coordinate in space
- upoint xy; // xy coordinate on the projected plane
- vector3d normal; // average normal to the vertex
- WORD nCount; // how many normals were added to compute the average
-
- WORD mKind; // isVertex or isNormal?
-
- // =======================================================================
- // Constructors
- // =======================================================================
-
- vertex();
- vertex(WORD x, WORD y, WORD z, WORD inKind);
-
- void setTo(WORD x, WORD y, WORD z, WORD inKind);
-
- void xform2d();
- void setNewOrigin(vertex *p);
- void globalXform2origin(vertex *p);
- void copyOrigin(vertex *p);
-
- // =======================================================================
- // Rotations/Translations stuff
- // =======================================================================
-
- void localRotate(matrix3d mat);
- void translate(WORD dX, WORD dY, WORD dZ);
-
- // =======================================================================
- // Normal computations
- // =======================================================================
-
- void zeroNormal();
- void addNormal(WORD dX, WORD dY, WORD dZ);
- void avgNormal();
-
- virtual ~vertex();
-
- protected:
- };
-
- WORD dotProduct(const vector3d *p1, const vector3d *p2);
-
- typedef struct
- {
- WORD p1, p2, p3, color;
- } polyRec;
-
- enum {
- sNone = 0,
- sWire,
- sFlat,
- sGouraud,
- sTexMap,
- sGouraudTexMap
- };
-
- enum {
- tx32x32,
- tx64x64,
- tx128x128,
- tx256x256,
- tx512x512
- };
-
- class polygon : public ListNode
- {
- public:
-
- vertex *p1, *p2, *p3, normal;
-
- polygon();
- polygon(vertex *v1, vertex *v2, vertex *v3);
-
- void calcThetaPhi(vector3d v, WORD &theta, WORD &phi);
-
- void setTo(vertex *v1, vertex *v2, vertex *v3);
-
- WORD calcAvgZ();
-
- void setNewOrigin(vertex *p);
-
- void localRotate(matrix3d mat);
- void globalRotate(matrix3d mat);
-
- void setGNormals();
-
- void renderGouraudTexMap();
- void renderTexMap();
- void renderGouraud();
- void renderWire();
- void renderFlat();
- void renderNone();
-
- void renderPoly(BYTE method);
- void applyTexture(WORD width, WORD height, WORD depth);
-
- ~polygon();
-
- WORD averageZ;
- protected:
- };
-
- typedef struct
- {
- WORD numPoints, numPolys;
- } objFileHeader;
-
- class object3d : public ListNode
- {
- public:
-
- object3d();
-
- void save(char *fname);
- void load(char *fname);
- void importV3D(char *fname);
- void importASC(char *fname);
-
- void addLocalPoint(WORD x, WORD y, WORD z, WORD inKind);
- void addLocalPoint(vertex *p);
-
- void addLocalPoly(WORD p1, WORD p2, WORD p3);
- void addLocalPoly(polygon *pg);
-
- WORD getPointNum(vertex *p);
- vertex *getPointAddr(WORD pNum);
-
- void localRotate();
- void makeRotMatrix(WORD alpha, WORD theta, WORD phi);
-
- void translate(WORD dX, WORD dY, WORD dZ);
- void setLocation(WORD x, WORD y, WORD z);
-
- void sortPlanes();
-
- void zeroGNormals();
- void setGNormals();
- void display();
-
- void applyTexture();
- void calcBounds(WORD &width, WORD &height, WORD &depth);
- virtual ~object3d();
-
- LinkList points;
- LinkList polys;
- WORD count, xDeg, yDeg, zDeg;
-
- protected:
- Stack stack1[256], stack2[256];
- matrix3d mat;
- };
-
- class world3d
- {
- public:
-
- world3d();
- virtual ~world3d();
- void globalRotate(WORD tX, WORD tY, WORD tZ);
- void insertObject(object3d *object);
- void deleteObject(object3d *object, BOOL doDisposeIt = TRUE);
- void draw();
-
- protected:
-
- LinkList objects;
- WORD xDeg, yDeg, zDeg;
- };
- class viewPoint
- {
-
- public:
-
- vector3d location, light, view;
-
- viewPoint();
-
- void rotate(int tX, int tY, int tZ);
- void translate(int dX, int dY, int dZ);
-
- ~viewPoint();
-
- private:
-
-
- };
-
- #define ABS(x) (((x) < 0) ? -(x) : (x))
-
- extern world3d world;
- extern viewPoint camera;
-
- extern WORD matrix[9];
- extern WORD *perspect;
-
- extern Point middle;
- extern Ptr baseAddr;
- extern short rowBytes;
-
- #define SQR(x) ((x) * (x))
- #define SQRT(x) (sqrt(x))
-
- extern WORD startx[480], endx[480], startcol[480], endcol[480];
-
- void ASM_GouraudPoly(upoint p1, upoint p2, upoint p3);
- void C_GouraudPoly(upoint p1, upoint p2, upoint p3);
- void C_TexturePoly(upoint p1, upoint p2, upoint p3);
-
-
-